package com.leetcode;

import javax.xml.bind.annotation.XmlInlineBinaryData;
import java.util.Arrays;

/**
 * Created by Z-hong on 2022/9/21.
 */

//没做出来！！！！！！！！！！！！！！！！！！！！

public class LeetCode854 {


    public static int COUNT=0;
    public static char[] ss1;
    public int kSimilarity(String s1, String s2) {
        int min=10000;
        ss1 = s1.toCharArray();
        char[] ss2 = s2.toCharArray();
        for (int i = 0; i < ss2.length; i++) {
            if(ss2[i]==ss1[i])ss2[i]=0;
            COUNT++;
        }
        for(int i=0;i<ss2.length;i++){
            for (int j = 0; j < ss2.length; j++) {
               min=Math.min(min, getMax(ss2, i,j ,0 ));
            }
        }

        return min;
    }

    public int getMax(char[] ss2,int r,int l,int count){
        if (COUNT==ss2.length)return count;
        char mid;
        mid=ss2[r];
        ss2[r]=ss2[l];
        ss2[l]=mid;
        if (ss2[r]==ss1[r]){ss2[r]=0;COUNT++;}
        if (ss2[l]==ss1[l]){ss2[l]=0;COUNT++;}
        count++;
        for(int i=r;i<ss2.length;i++){
            for (int j = l; j < ss2.length; j++) {
                if(ss2[r]==0||ss2[l]==0)continue;
                count= Math.min(count,getMax(ss2, i, l, count));
            }
        }
        return count;
    }

}
